﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class member_member : System.Web.UI.Page
{
    Common Init = new Common();
    MsSqlHelper mssql = new MsSqlHelper();
    public string EnterpriseName = "";
    public string UserID = "";
    public string UserPower = "";
    public string Footer = "";
    public string keyword="";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Init.islogin(ref UserID, ref EnterpriseName, ref UserPower))
        {
            Response.Redirect("/Login.aspx");
        }
        this.EnableViewState = false;
        Response.Write(Init.InitDefault());
        Footer = Init.IndexFooter();
        keyword = Request.QueryString["keyword"];
        if (!string.IsNullOrEmpty(keyword))
        {
            if (UserPower.Contains("member"))
            {            
                DataSet ds = DataGroup(keyword);
                GridView1.DataSource = ds;
                GridView1.DataKeyNames = new string[] { "ID" };//主键
                int recordCount = ds.Tables[0].Rows.Count;
                GridView1.DataBind();
            }
            else
            {
                Literal1.Text = "您没有权限，请联系系统管理员";
            }
        }  
    }
    //分页
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView1.PageIndex = e.NewPageIndex;
        DataSet ds = DataGroup(keyword);
        GridView1.DataSource = ds;
        GridView1.DataKeyNames = new string[] { "ID" };//主键
        int recordCount = ds.Tables[0].Rows.Count;
        GridView1.DataBind();
    }

    //展示
    public DataSet DataGroup(string keyword)
    {
        string sql = "select ID,UserID,UserPass,UserState,EnterpriseName,UserPower,LastIP,LastDate,'membermodify.aspx?id='+cast(id as char(10)) as url ";
        sql += " from [Web_User](nolock)";
        if (!string.IsNullOrEmpty(keyword))
        {
            sql += " where (UserID like '%" + keyword + "%' or EnterpriseName like '%" + keyword + "%')";
        }        

        if (Init.IsDebug)
        {
            ResultDeBug.Text = sql;
        }
        DataSet dss = mssql.ExecuteDs(sql);
        return dss;
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        DataSet ds = DataGroup(keyword);
        GridView1.DataSource = ds;
        GridView1.DataKeyNames = new string[] { "ID" };//主键
        int recordCount = ds.Tables[0].Rows.Count;
        GridView1.DataBind();
    } 
}